package com.example.juc.big_talk_concurrent.chapter7.article2;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Test2 {
    static ExecutorService singleThreadPool = Executors.newSingleThreadExecutor();

    public static void main(String[] args) {
        // 执行任务
        for (int i = 0; i < 10; i++) {
            int finalI = i;
            singleThreadPool.execute(() -> {
                System.out.println("任务 " + finalI + " 被执行");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                }
            });
        }

        singleThreadPool.shutdown();
    }
}
